import 'package:fate_blind_box/utils/default/common_config.dart';
import 'package:flutter/material.dart';

import '../../../theme/theme_color.dart';

import 'dart:async';
import 'dart:io';
import 'package:url_launcher/url_launcher.dart';
import '../../../utils/loading.dart';

class CustomShareView extends StatelessWidget {

  static showShareView(BuildContext context) {
    final size = MediaQuery.of(context).size;
    showModalBottomSheet(context: context,
        backgroundColor: Colors.white.withAlpha(0),
        elevation: 2,
        builder: (BuildContext context){
          return  SingleChildScrollView(
            child:
            Container(
                width: size.width,
                height: 282,
                padding: const EdgeInsets.only(bottom: 0,left: 0,right: 0),
                color: Colors.white,
                child:
                Align(
                  alignment: Alignment.bottomCenter,
                  child: Container(
                    // height: 282,
                    color: Colors.white,
                    child: Column(
                      children: [
                        Container(

                          margin: const EdgeInsets.fromLTRB(17, 20, 17, 0),
                          color: const Color(0xFFF6F8FA),
                          child: const TextField(
                            // controller: _textController,
                            // maxLength: 11,
                            // keyboardType: TextInputType.phone,
                            cursorColor: Color(0xFFFB6D99),
                            style: TextStyle(
                                fontSize: 12,
                                color: Color(0xFF222222)
                            ),
                            decoration: InputDecoration(
                              hintText: "红娘自助餐",
                              counterText: "",
                              border: InputBorder.none,
                              hintStyle: TextStyle(color: Color(0xFF999999)),
                              fillColor: Color(0xffF1F3FB),
                              filled: true,
                            ),
                          ),
                        ),

                        const SizedBox(height: 20,),
                        Container(
                          margin: const EdgeInsets.only(left: 17),
                          height: 66,
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Row(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                children: [
                                  Row(
                                      crossAxisAlignment: CrossAxisAlignment.start,
                                      children: [
                                        ClipRRect(
                                          // borderRadius: BorderRadius.circular(11),
                                          child: Image.asset(
                                            "images/ic_canting.png",
                                            // Provider.fixAvatar(itemData['avatarImg']),
                                            width: 50,
                                            height: 50,
                                            fit: BoxFit.cover,
                                          ),
                                        ),
                                        Column(

                                          crossAxisAlignment: CrossAxisAlignment.start,

                                          children: [

                                            Row(

                                              children: [
                                                const SizedBox(width: 8,),
                                                SizedBox(
                                                  width:200,
                                                  child:Text('红娘自助晚餐', style: TextStyle(fontSize: 16, color: ThemeColor.textColor,overflow: TextOverflow.ellipsis),),
                                                )
                                              ],
                                            ),
                                            const SizedBox(height: 5,),

                                            Row(

                                              children: [
                                                const SizedBox(width: 8,),

                                                const SizedBox(width: 5,),
                                                Text('距您27.0km', style: TextStyle(fontSize: 14, color: ThemeColor.textColorSecond,overflow: TextOverflow.ellipsis),),
                                                const SizedBox(width: 3,),
                                              ],
                                            )
                                          ],
                                        )
                                      ]
                                  ),
                                ],
                              ),
                            ],
                          ),
                        ),

                        Visibility(
                          visible: CommonConfig.isShowPay(),
                          child: GestureDetector(
                              child: Container(
                                alignment: Alignment.center,
                                margin: const EdgeInsets.fromLTRB(10, 20, 10, 0),
                                padding: const EdgeInsets.symmetric(vertical: 10),
                                height: 45,
                                // width: size.width -80,
                                decoration: ShapeDecoration(
                                  shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(22.5)),
                                  color: const Color(0xFF7F69D9),
                                ),

                                child: const Text('到这去',style: TextStyle(color: Colors.white,fontSize: 16),),
                              ),

                              onTap: (){

                                showModalBottomSheet(
                                  context: context,
                                  builder: (BuildContext context) {
                                    return SizedBox(
                                        height: 220.0,
                                        child: Container(
                                            alignment: Alignment.center,
                                            child: Column(
                                              children: [

                                                GestureDetector(
                                                    onTap: (){
                                                      gotoTencentMap(39.909187, 116.397451);
                                                    },
                                                    child: Container(
                                                      alignment: Alignment.center,
                                                      width: size.width,
                                                      height: 55,
                                                      color: Colors.white,
                                                      child: const Text('腾讯地图'),
                                                    )
                                                ),
                                                Divider(color: ThemeColor.sendMsgColor,height: 1,),
                                                GestureDetector(
                                                    onTap: (){
                                                      gotoGaoDeMap('四惠东',39.909187, 116.397451);
                                                    },
                                                    child: Container(
                                                      alignment: Alignment.center,
                                                      width: size.width,
                                                      height: 60,
                                                      color: Colors.white,
                                                      child: const Text('高德地图'),
                                                    )
                                                ),
                                                Divider(color: ThemeColor.sendMsgColor,thickness: 7,height: 1,),
                                                GestureDetector(
                                                    onTap: (){
                                                      Navigator.pop(context);
                                                    },
                                                    child: Container(
                                                      alignment: Alignment.center,
                                                      width: size.width,
                                                      height: 55,
                                                      child: const Text('取消'),
                                                    )
                                                )

                                              ],
                                            )
                                        )
                                    );
                                  },
                                );
                              }

                          ),
                        ),
                      ],
                    ),
                  ),
                )
            ),
          );


        }
    );

  }

  /// 高德地图
  static Future<bool> gotoGaoDeMap(keywords,longitude, latitude) async {
    var url = '${Platform.isAndroid ? 'android' : 'ios'}amap://navi?sourceApplication=amap&lat=$latitude&lon=$longitude&dev=0&style=2';

    bool canLaunchUrl = await canLaunch(url);

    if (!canLaunchUrl) {
      toast('未检测到高德地图~');

      return false;
    }

    await launch(url);

    return true;
  }


  /// 腾讯地图
  static Future<bool> gotoTencentMap(longitude, latitude) async {
    var url = 'qqmap://map/routeplan?type=drive&fromcoord=CurrentLocation&tocoord=$latitude,$longitude&referer=IXHBZ-QIZE4-ZQ6UP-DJYEO-HC2K2-EZBXJ';
    bool canLaunchUrl = await canLaunch(url);

    if (!canLaunchUrl) {
      toast('未检测到腾讯地图~');
      // ToastUtil.show('未检测到腾讯地图~');
      return false;
    }

    await launch(url);

    return canLaunchUrl;
  }

  _dismiss(BuildContext context) {
    Navigator.pop(context);
  }

  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

